/* Receipts-ByOffice.do */

* Global options.
global OUTREG2OPTIONS tex(fragment) 2aster auto(2) rdec(3) label
global TABLELOC "."
global FE_options fe cluster(Party_State)

use "Receipts-ByOffice.dta", clear

*
* tsset Diff in diff by party-state-year.
*
tsset Party_State_office cycle, delta(2)

*****************************
* Regression models
*****************************

* Loop over different specifications.
forvalues modelgroups = 1(1)1 {
  * Determine specification.
	if `modelgroups'==1 {
    * My coding of less_costly and nonpartisan.
    local EVs = "less_costly_primary nonpartisan_primary"
    local outregfile "$TABLELOC/TableA09"
    local note "Excluded category is institutions most costly for individual participation."
  }

  local keepvars "`EVs'"
  local repl "replace"
  * Loop over values of office.
  levelsof office, local(levels)
  foreach l of local levels {
    di "Office `l'"
    xtreg total_receipts `EVs' i.cycle if office == "`l'", $FE_options
     outreg2 using "`outregfile'.tex", $OUTREG2OPTIONS ctitle("`l',Candidate,Receipts,(1000s)") sdec(0) addnote("OLS coefficients with robust standard errors clustered on state-party in parentheses.","Money dependent variables in thousands of dollars.","`note'") nocons keep(`keepvars') addtext("Party-state FEs","Yes","Election cycle FEs","Yes") `repl'
    local repl "append"
    * Log version.
    xtreg logreceipts `EVs' i.cycle if office == "`l'", $FE_options
     outreg2 using "`outregfile'.tex", $OUTREG2OPTIONS ctitle("`l',Log,Receipts") sdec(2) nocons keep(`keepvars') addtext("Party-state FEs","Yes","Election cycle FEs","Yes") append
    * Percentage change.
    foreach var of varlist `EVs' {
      di "Estimated percentage change of `var':" _n 100*(exp(_b[`var'])-1)
    }

    xtreg num_givers `EVs' i.cycle if office == "`l'", $FE_options
     outreg2 using "`outregfile'.tex", $OUTREG2OPTIONS ctitle("`l',Count of, Contributors") sdec(0) nocons keep(`keepvars') addtext("Party-state FEs","Yes","Election cycle FEs","Yes") append
    
    * Summary statistics.
    summ total_receipts if office == "`l'", detail
    summ num_givers if office == "`l'", detail
    
  }
}
